using UnityEngine;
using UnityEngine.Audio;

public class VolumeController : MonoBehaviour
{
	public static VolumeController instance;

	public AudioMixer musicMixer;

	public AudioMixer soundMixer;

	public static string keyVolSound = "VolumeSound";

	public static string keyVolMusic = "VolumeMusic";

	public static string keySoundOn = "SoundOn";

	public static string keyMusicOn = "MusicOn";

	private static float _volumeSound = 1f;

	private static float _volumeMusic = 1f;

	private static bool _soundOn = true;

	private static bool _musicOn = true;

	public static float volumeMusic
	{
		get
		{
			return _volumeMusic;
		}
	}

	public static bool IsSoundEnable
	{
		get
		{
			if (VolumeSound.Equals(0f))
			{
				return false;
			}
			return true;
		}
	}

	public static bool SoundOn
	{
		get
		{
			if (!PlayerPrefs.HasKey(keySoundOn))
			{
				return true;
			}
			return Load.LoadBool(keySoundOn);
		}
		set
		{
			_soundOn = value;
			Save.SaveBool(keySoundOn, _soundOn);
		}
	}

	public static bool MusicOn
	{
		get
		{
			if (!PlayerPrefs.HasKey(keyMusicOn))
			{
				return true;
			}
			return Load.LoadBool(keyMusicOn);
		}
		set
		{
			_musicOn = value;
			Save.SaveBool(keyMusicOn, _musicOn);
		}
	}

	public static float VolumeSound
	{
		get
		{
			return (!SoundOn) ? 0f : Load.LoadFloat(keyVolSound);
		}
		set
		{
			_volumeSound = value;
			if (_volumeSound > 1f)
			{
				_volumeSound = 1f;
			}
			if (_volumeSound < 0f)
			{
				_volumeSound = 0f;
			}
			if (value > 0f)
			{
				Save.SaveFloat(keyVolSound, _volumeSound);
			}
			if (instance != null)
			{
				instance.soundMixer.SetFloat("VolSound", ConvSliderToSound(_volumeSound));
			}
		}
	}

	public static float VolumeMusic
	{
		get
		{
			return (!MusicOn) ? 0f : Load.LoadFloat(keyVolMusic);
		}
		set
		{
			_volumeMusic = value;
			if (_volumeMusic > 1f)
			{
				_volumeMusic = 1f;
			}
			if (_volumeMusic < 0f)
			{
				_volumeMusic = 0f;
			}
			if (value > 0f)
			{
				Save.SaveFloat(keyVolMusic, _volumeMusic);
			}
			if (instance != null)
			{
				instance.musicMixer.SetFloat("VolMusic", ConvSliderToSound(_volumeMusic));
			}
		}
	}

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		VolumeSound = VolumeSound;
		VolumeMusic = VolumeMusic;
	}

	private void OnDestroy()
	{
		instance = null;
	}

	public static float ConvSliderToSound(float val)
	{
		val = Mathf.Sqrt(Mathf.Sqrt(val));
		return val * 80f - 80f;
	}
}
